<%@ page import="java.lang.String"%>
<%@ page import="net.seabookchen.service.UserIdentificationService"%>
<%@ page import="com.google.appengine.api.users.UserService"%>
<%@ page import="com.google.appengine.api.users.UserServiceFactory"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	UserService userService = UserServiceFactory.getUserService();
	String username = (String) session.getAttribute("username");
	if (request.getUserPrincipal() != null) {
		session.setAttribute("username", userService.getCurrentUser().getNickname());
		session.setAttribute("email", userService.getCurrentUser().getEmail());
		session.setAttribute("isAdmin",
				UserIdentificationService.isAdminLoggedIn());
	} else {
		session.setAttribute("username", null);
		session.setAttribute("email", null);
		session.setAttribute("isAdmin", false);
	}
	
	String logReturnUrl = request.getRequestURI();
			
	if (request.getQueryString() != null && request.getQueryString().length() > 0) {
		logReturnUrl = logReturnUrl + "?" + request.getQueryString();
	}
		
%>
<div id="header-wrapper">
<header id="main-header" class="group">
	<a href="/about.jsp" id="seabook-avarta"></a>

	<div id="login">
		<c:choose>
			<c:when test="${not empty username}">
			<span class="welcome">Welcome back ${username} !!!</span>
				<a class="button-link"
					href="<%=userService.createLogoutURL(logReturnUrl)%>">logout</a>
		</c:when>
			<c:otherwise>
				<a class="button-link"
					href="<%=userService.createLoginURL(logReturnUrl)%>">
					Haven't logged in? </a>
			</c:otherwise>
		</c:choose>
	</div>
</header>

<nav id="main-nav">
	<ul>
		<li><a href="home.jsp">Home</a></li>
		<li><a href="blog.jsp">Blog</a></li>
		<li><a href="resume.jsp">Resume</a></li>
		<li><a href="playground.jsp">Playground</a></li>
		<li><a href="about.jsp">About</a></li>
		<a name="top"></a>
	</ul>
</nav>
</div>